<script>
export default {
  name: 'XTableActionDeleteButton'
}
</script>
<script setup>
import { ElMessage, ElMessageBox } from 'element-plus'
import { inject, defineProps } from 'vue'

const { label } = defineProps(['label'])

const store = inject('store')
const row = inject('row')

const deleteHandler = async function () {
  // 删除操作
  try {
    await store.removeById(row.id)
    await store.refresh()
  } catch (error) {
    ElMessage.error('删除失败')
  }
}
</script>

<template>
  <el-popconfirm
    width="300"
    :title="`确定要删除${label ? '用户 ' + row[label] + ' ' : '该用户'}吗？`"
    @confirm="deleteHandler(row.id)"
  >
    <template #reference>
      <el-button
        type="primary"
        icon="Delete"
        v-has="'btn.User.remove'"
      >
        删除
      </el-button>
    </template>
  </el-popconfirm>
</template>

<style scoped lang="scss">
// start
</style>
